/*
 * @Author: '浪川' '1214391613@qq.com'
 * @Date: 2025-06-18 16:37:49
 * @LastEditors: '浪川' '1214391613@qq.com'
 * @LastEditTime: 2025-07-04 17:13:25
 * @FilePath: \passiflora-edulis-sims\src\boot\axios.ts
 * @Description: 实例化 Axios 对象
 *
 * Copyright (c) 2025 by '1214391613@qq.com', All Rights Reserved.
 */
import { defineBoot } from '#q-app/wrappers'
import axios, { type AxiosInstance } from 'axios'

declare module 'vue' {
  interface ComponentCustomProperties {
    $axios: AxiosInstance
    $api: AxiosInstance
  }
}

// Be careful when using SSR for cross-request state pollution
// due to creating a Singleton instance here;
// If any client changes this (global) instance, it might be a
// good idea to move this instance creation inside of the
// "export default () => {}" function below (which runs individually
// for each client)
const api = axios.create({
  baseURL: process.env.DEV ? '/api' : 'https://your-production-api.com',
  withCredentials: false, // 如果需要携带凭证(cookie等)
  headers: {
    'Content-Type': 'application/json',
    // 其他自定义头部
  },
})

export default defineBoot(({ app }) => {
  // for use inside Vue files (Options API) through this.$axios and this.$api

  app.config.globalProperties.$axios = axios
  // ^ ^ ^ this will allow you to use this.$axios (for Vue Options API form)
  //       so you won't necessarily have to import axios in each vue file

  app.config.globalProperties.$api = api
  // ^ ^ ^ this will allow you to use this.$api (for Vue Options API form)
  //       so you can easily perform requests against your app's API
})

export { api }
